package com.mall.huohuo.process.container;

import com.mall.huohuo.process.Node;
import com.mall.huohuo.process.Pipeline;
import com.mall.huohuo.process.annotation.NodeDefinition;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zycoding
 * @version AbstractNodeContainer.java, v 0.1 2020-08-17 22:38 zycoding
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
public abstract class AbstractNodeContainer implements NodeContainer {

    protected final  Map<String, Pipeline> piplineMap = new ConcurrentHashMap<>(16);

    public  void registerPipline(NodeDefinition node, Node bean, String entryName) {

        Pipeline pipline = piplineMap.get(entryName);

        if (Objects.isNull(pipline)) {
            pipline = new Pipeline();
        }
        pipline.registryNode(bean);

        piplineMap.put(entryName,pipline);
    }

    @Override
    public Pipeline getPipline(String entryName) {
        return piplineMap.get(entryName);
    }
}
